﻿using System;
using System.Collections;
using System.Threading;
using System.Windows.Forms;
using System.Data;
using StockTrader.DAL.HoseAdapter.FileParser;
using System.Collections.Generic;
using StockTrader.DAL.HoseAdapter.FileParser.Structure;

namespace StockTrader.DAL.HoseAdapter.FileViewer.DataAccess
{
    public class DataAccessClient
    {
        private GetCustomerByIdDelegate _invokeMe;
        private DataGridView _grid;
        private Type _className;
        private DateTime _seletected;

        private delegate ArrayList GetCustomerByIdDelegate(DateTime selected, Type className);

        public DataAccessClient(DataGridView grv, DateTime selected, Type className)
        {
            _grid = grv;
            _className = className;
            _seletected = selected;
            _invokeMe = new GetCustomerByIdDelegate(FileEngineer.RetrieveFileInfo);
        }
        public void Execute()
        {
            //Update UI here
            _invokeMe.BeginInvoke(_seletected, _className, this.CallBack, null);
        }
        private void CallBack(IAsyncResult ar)
        {
            ArrayList list = _invokeMe.EndInvoke(ar);

            foreach (OrderCancellation order in list)
            {
                
            }

            //Update UI here
            MethodInvoker updateGrid = delegate
            {
                _grid.DataSource = list;
            };
            if (_grid.InvokeRequired)
                _grid.Invoke(updateGrid);
            else
                updateGrid();
        }
    }
}
